import { Middleware } from 'koa'

export default function requestLog(): Middleware {
    return async (ctx, next) => {
        const start = Date.now()
        await next()
        const elapsed = Date.now() - start

        //输出请求日志
        console.log(`${ctx.status} ${elapsed}ms [${ctx.method}] ${ctx.url}`)
    }
}
